package com.sywb.chuangyebao.view.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.contract.MyManuscriptContract;

import org.bining.footstone.rxjava.rxbus.annotation.Tag;
import org.bining.footstone.rxjava.rxbus.thread.ThreadMode;
import org.bining.footstone.rxjava.rxbus.annotation.Subscribe;
public class ManusrciptStypeFragment extends BaseRefreshFragment<MyManuscriptContract.MyManuscriptPresenter> implements MyManuscriptContract.MyManuscriptView {

    private int titleStyle;
    private int tabStyle;

    /**
     * Fragment 实例
     */
    public static ManusrciptStypeFragment newInstance(Object... pramars) {
        ManusrciptStypeFragment fragment = new ManusrciptStypeFragment();
        fragment.setArguments(getBundle(pramars));
        return fragment;
    }

    @Override
    public void initView(View view, Bundle bundle) {
        super.initView(view, bundle);
        if (bundle == null) {
            bundle = getArguments();
        }
        titleStyle = bundle.getInt("p0");
        tabStyle = bundle.getInt("p1");
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        outState.putInt("p0", titleStyle);
        outState.putInt("p1", tabStyle);
        super.onSaveInstanceState(outState);
    }

    @Override
    public String getStatisticsIdentity() {
        return titleStyle == 0 ? "我的文章" : "我的视频";
    }

    @Override
    public boolean useRxBus() {
        return true;
    }

    @Override
    public int getTitleStype() {
        return titleStyle;
    }

    @Override
    public int getTabStype() {
        return tabStyle;
    }
    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_ARTICLE)})
    public void updateArticle(String data) {
        mPresenter.pageNo=1;
        mPresenter.listMyArticleOrVideo();
    }

    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_VIDEO_SAVE)})
    public void updateVideo(String data) {
        mPresenter.pageNo=1;
        mPresenter.listMyArticleOrVideo();
    }
}
